<script lang="ts" setup>
import router from '@/router'
import axios from 'axios'
import { reactive, ref } from 'vue'

// do not use same name with ref
const form = ref({
  name: '',
  password: ''
})

const onSubmit = () => {
  console.log(form.value)

  axios.post("http://localhost:8080/api/login",form.value).then(res=>{
    console.log(res.data)
    localStorage.setItem("token",res.data.data.token)
    localStorage.setItem("username",res.data.data.username)
    localStorage.setItem("userid",res.data.data.userid)
    router.push("/")
  }).catch(err=>{
    console.log(err.response.data.message)
    // alert(err.response.data.message)

  })
}
</script>

<template>
    <h1>系统登录</h1>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="用户名">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" />
      </el-form-item>
      
      
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </template>

<style>
</style>